/**
 * 
 */
package com.googlecode.pcapj;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Represents the EthernetII protocol is defined in the data link layer. 
 */
public class Ethernet implements DataLinkLayer<EthernetPacket> {
	/**
	 * Defines frame types.
	 */
	public static class FramTypes {
		/**
		 * IPv4
		 */
		public static final short IP = (short)0x0800;
		/**
		 * IPv6
		 */
		public static final short IPv6 = (short)0x86dd;
	}
	
	private LinkedHashMap<Short, NetworkLayer<? extends Packet>> neworkLayers = new LinkedHashMap<Short, NetworkLayer<? extends Packet>>();
	
	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.DataLinkLayer#getType()
	 */
	public int getType() {
		return 1;
	}
	
	/* (non-Javadoc)
	 * @see com.googlecode.pcapj.PacketFactory#newPacket(byte[], int, int)
	 */
	public EthernetPacket newPacket(byte[] buffer, int offset, int length) {
		EthernetPacketImpl ethernetPacket = new EthernetPacketImpl(buffer, offset, length);
		PacketFactory<? extends Packet> packetFactory = neworkLayers.get(ethernetPacket.getFrameType());
		if(packetFactory == null){
			packetFactory = PacketFactoryImpl.DEFAULT_FACTORY;
		}
		ethernetPacket.setPacketFactory(packetFactory);
		return ethernetPacket;
	}
	/**
	 * Gets the editable mappings of a frame type and a network layer protocol.
	 * @return the mappings of a frame type and a network layer protocol.
	 */
	public Map<Short, NetworkLayer<? extends Packet>> getNeworkLayers() {
		return neworkLayers;
	}
	
}
